package com.zhifa.hdtyg_cdgl.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
public class LoginController {


    @RequestMapping("/")
    public String index(){
        return "index";
    }

    /**
     * 模拟用户登录
     * @param userId
     * @param httpSession
     * @return
     */
    @ResponseBody
    @RequestMapping("/siteLogin/{siterole}/{user_id}")
    public  Map<String,Object> login(@PathVariable(value = "user_id") Integer user_id,@PathVariable(value = "siterole") String siterole, HttpSession httpSession){
        /**
         * 从httpSession中获取用户信息id
         */

            httpSession.setAttribute("siterole",siterole);
            httpSession.setAttribute("user_id",user_id);
            System.out.println("模拟用户登录："+ siterole+"  id="+user_id);
            boolean b=true;
        /**
             * 模拟管理员登录
             */
        Map<String,Object>map=new HashMap<>();
        if (b){

            map.put("state","success");
        }else {
            map.put("state","fail");
        }
        return map;

        //return "redirect:/site_main.html";
    }

}
